#include <cstdio>

#define lowbit(x) (x & -x)
const int N = 100005;
int n, m, cnt, L, R, a[N], lpos[N], rpos[N], rt[N], pos[N];
long long ans;

struct Node {
  int ls, rs, val;
} tr[N << 7];

void modify(int &x, int l, int r, int k, bool ins) {
  if (!x) x = ++cnt;
  ins ? tr[x].val++ : tr[x].val--;
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (k <= mid)
    modify(tr[x].ls, l, mid, k, ins);
  else
    modify(tr[x].rs, mid + 1, r, k, ins);
}

inline int query(int l, int r, int k, bool pre) {
  L = R = 0;
  for (int i = l - 1; i; i -= lowbit(i)) lpos[++L] = rt[i];
  for (int i = r; i; i -= lowbit(i)) rpos[++R] = rt[i];
  int mid, sum = 0;
  l = 1, r = n;
  while (l != r) {
    mid = (l + r) >> 1;
    if (k <= mid) {
      if (pre) {
        for (int i = 1; i <= L; ++i) sum -= tr[tr[lpos[i]].rs].val;
        for (int i = 1; i <= R; ++i) sum += tr[tr[rpos[i]].rs].val;
      }
      for (int i = 1; i <= L; ++i) lpos[i] = tr[lpos[i]].ls;
      for (int i = 1; i <= R; ++i) rpos[i] = tr[rpos[i]].ls;
      r = mid;
    } else {
      if (!pre) {
        for (int i = 1; i <= L; ++i) sum -= tr[tr[lpos[i]].ls].val;
        for (int i = 1; i <= R; ++i) sum += tr[tr[rpos[i]].ls].val;
      }
      for (int i = 1; i <= L; ++i) lpos[i] = tr[lpos[i]].rs;
      for (int i = 1; i <= R; ++i) rpos[i] = tr[rpos[i]].rs;
      l = mid + 1;
    }
  }
  return sum;
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("P3157 [CQOI2011]动态逆序对.in", "r", stdin);
  freopen("P3157 [CQOI2011]动态逆序对.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    pos[a[i]] = i;
  }
  for (int i = 1, tmp = 1; i <= n; tmp = ++i) {
    ans += query(1, i - 1, a[i], true);
    while (tmp <= n) {
      modify(rt[tmp], 1, n, a[i], true);
      tmp += lowbit(tmp);
    }
  }
  printf("%lld\n", ans);
  for (int i = 1, tmp, x; i < m; ++i) {
    scanf("%d", &x);
    ans -= query(1, pos[x] - 1, x, true);
    ans -= query(pos[x] + 1, n, x, false);
    printf("%lld\n", ans);
    tmp = pos[x];
    while (tmp <= n) {
      modify(rt[tmp], 1, n, x, false);
      tmp += lowbit(tmp);
    }
  }
  return 0;
}